package com.seveneight.baijiesteward.ui.user.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.base.BaseFragmentBack;
import com.seveneight.baijiesteward.bean.UserBean;
import com.seveneight.baijiesteward.utils.GlideLoader;
import com.seveneight.baijiesteward.utils.NumberUtil;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by user1 on 2018/2/9.
 */

public class UserInfoFragment extends BaseFragmentBack implements View.OnClickListener {

    private ImageView iv_back;
    private TextView tv_title;
    private CircleImageView ci_head;
    private TextView tv_nickName;
    private TextView tv_mobile;
    private TextView tv_merchantNo;
    private TextView tv_registDate;
    private TextView tv_identifyDate;
    private TextView tv_identifyStatu;
    private TextView tv_rebackMoney;
    private TextView tv_rebackPersent;
    private TextView tv_highPersent;
    private TextView tv_email;
    private TextView tv_address;

    @Override
    protected int getContentView() {
        return R.layout.fragment_userinfo;
    }

    public static UserInfoFragment newInstance() {
        Bundle args = new Bundle();
        UserInfoFragment fragment = new UserInfoFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initView() {
        iv_back = findView(R.id.iv_back);
        tv_title = findView(R.id.tv_title);
        tv_title.setText("用户信息");
        ci_head = findView(R.id.ci_head);
        tv_nickName = findView(R.id.tv_nickName);
        tv_mobile = findView(R.id.tv_mobile);
        tv_merchantNo = findView(R.id.tv_merchantNo);
        tv_registDate = findView(R.id.tv_registDate);
        tv_identifyDate = findView(R.id.tv_identifyDate);
        tv_identifyStatu = findView(R.id.tv_identifyStatu);
        tv_rebackMoney = findView(R.id.tv_rebackMoney);
        tv_rebackPersent = findView(R.id.tv_rebackPersent);
        tv_highPersent = findView(R.id.tv_highPersent);
        tv_email = findView(R.id.tv_email);
        tv_address = findView(R.id.tv_address);
    }

    @Override
    protected void initData() {
        UserBean bean = setting.getUserInfo();
        if (!TextUtils.isEmpty(setting.getHeadImgUrl())) {
            GlideLoader.displayImg(mContext, setting.getHeadImgUrl(), ci_head);
        } else {
            GlideLoader.displayImg(mContext, R.mipmap.user_head, ci_head);
        }
        tv_nickName.setText(bean.getRealName());
        tv_mobile.setText(bean.getMobilePhone());
        tv_merchantNo.setText(bean.getMerchantNo());
        tv_registDate.setText(bean.getRegisterTime());
        tv_rebackMoney.setText(bean.getBrokerage() + "元/笔");
        tv_email.setText(bean.getEmail());
        tv_identifyDate.setText(bean.getAuthTime());
        tv_address.setText(bean.getAddress());
        tv_rebackPersent.setText(NumberUtil.getPercentFormat(bean.getRate()));
        tv_highPersent.setText(NumberUtil.getPercentFormat(bean.getRate()));
        if (bean.getAuthStatus().equals("0")) {
            tv_identifyStatu.setText("未认证");
        } else if (bean.getAuthStatus().equals("-1")) {
            tv_identifyStatu.setText("审核中");
        } else if (bean.getAuthStatus().equals("1")) {
            tv_identifyStatu.setText("已认证");
        } else {
            tv_identifyStatu.setText("审核失败");
        }
    }

    @Override
    protected void setListener() {
        iv_back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                _mActivity.onBackPressed();
                break;
        }
    }
}
